﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using Axial;
using Axial.DOM;

namespace AxialWeb
{
	public struct Point
	{
		public int X;
		public int Y;
	}

	public partial class DomEvent : System.Web.UI.Page
	{
		public void Startup()
		{
			pnlTest.AddHandler(ClientEvent.MouseDown, AlertSomething);
		}

		public bool AlertSomething(Event e)
		{
			Window.Alert("cursor x: " + GetPosition(e).X);
			return true;
		}

		public Point GetPosition(Event e)
		{
			if (e == null)
				e = Window.Event;
			//this doesn't work in Axial yet
			//e = e ?? Window.Event;
			var cursor = new Point { X = 0, Y = 0 };
			if (e.PageX != null)
			{
				cursor.X = e.PageX.Value;
				cursor.Y = e.PageY.Value;
			}
			else
			{
				cursor.X = e.ClientX + Document.ScrollLeft - Document.DocumentElement.ClientLeft;
				cursor.Y = e.ClientY + Document.ScrollTop - Document.DocumentElement.ClientTop;
			}
			return cursor;
		}
	}
}
